﻿using System;

namespace NetTopologySuite.Utilities
{
	public class Memory
	{
		public static long Total
		{
			get
			{
				return GC.GetTotalMemory(true);
			}
		}

		public static string TotalString
		{
			get
			{
				return Memory.Format(Memory.Total);
			}
		}

		public static string Format(long mem)
		{
			if ((double)mem < 2048.0)
			{
				return mem + " bytes";
			}
			if ((double)mem < 2097152.0)
			{
				return Memory.Round((double)mem / 1024.0) + " KB";
			}
			if ((double)mem < 2147483648.0)
			{
				return Memory.Round((double)mem / 1048576.0) + " MB";
			}
			return Memory.Round((double)mem / 1073741824.0) + " GB";
		}

		public static double Round(double d)
		{
			return Math.Ceiling(d * 100.0) / 100.0;
		}

		public const double KB = 1024.0;

		public const double MB = 1048576.0;

		public const double GB = 1073741824.0;
	}
}
